package com.zhang.proxy;

public class ProxySearcher implements Searcher{
    private RealSearcher searcher = new RealSearcher();
    private AccessValidator validator;
    private Logger logger;
    @Override
    public String doSearch(String userId, String keyword) {
        if(this.validator(userId)){
            String result = searcher.doSearch(userId,keyword);

            this.log(userId);
            return result;
        }
        else {
            return null;
        }
    }

    public boolean validator(String userId) {
        validator = new AccessValidator();
        return validator.validate(userId);
    }

    public void log(String userId) {
        logger = new Logger();
        logger.log(userId);
    }
}
